﻿using MESPro.Enums;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MESPro.Models
{
    /// <summary>
    /// 各类语言显示.这里增加语言后,需要同步SetLanguage()方法和Show()方法和Language枚举,然后全系统就能通用! ufo 增加语言:更新show方法和SetLanguage方法
    /// </summary>
    [Tenant("Default")]
    public class DisLanguage : EntityBaseId
    {
        #region 属性
        /// <summary>
        /// 状态 
        /// </summary>
        [SugarColumn(Length = 2, IsNullable = true),Browsable(false)]
        public string? Status { get; set; }
        /// <summary>
        /// 创建人Id
        /// </summary>
        [SugarColumn(ColumnDescription = "创建人ID", IsNullable = true)]
        [DisplayName("创建人Id"), ReadOnly(false), Description("创建人Id"), Category("\t\t\t\t\t\t\t\t属性配置"), Browsable(false)]
        public int CreateUserId { get; set; }



        /// <summary>
        /// 创建时间
        /// </summary>
        [SugarColumn(ColumnDescription = "创建时间", IsNullable = true)]
        [DisplayName("创建时间"), ReadOnly(false), Description("创建事件"), Category("\t\t\t\t\t\t\t\t属性配置"), Browsable(false)]
        public DateTime CreateTime { get; set; }

        /// <summary>
        /// 修改人Id
        /// </summary>
        [DisplayName("修改人Id"), ReadOnly(false), Description("修改人Id"), Category("\t\t\t\t\t\t\t\t属性配置"), Browsable(false)]
        [SugarColumn(IsNullable = true)]
        public int ModifyUserId { get; set; }



        /// <summary>
        /// 修改时间
        /// </summary>
        [DisplayName("修改时间"), ReadOnly(false), Description("修改时间"), Category("\t\t\t\t\t\t\t\t属性配置"), Browsable(false)]
        [SugarColumn(IsNullable = true)]
        public DateTime ModifyTime { get; set; }
        ///// <summary>
        ///// 状态 
        ///// </summary>
        //[SugarColumn(Length = 50, IsNullable = true)]
        //public string? Name { get; set; }
        /// <summary>
        /// 中文(大陆)
        /// </summary>
        [SugarColumn(Length = 150)]
        [DisplayName("中文")]
        public string? zh_CN { get; set; }

        /// <summary>
        /// 中文(台湾),一般表示繁体
        /// </summary>
        [DisplayName("中文_繁体")]
        [SugarColumn(Length = 150, IsNullable = true)]
        public string? zh_TW { get; set; }

        /// <summary>
        /// 英文 美国
        /// </summary>
        [DisplayName("英文")]
        [SugarColumn(Length = 150)]
        public string? en_US { get; set; }

        /// <summary>
        /// 日本
        /// </summary>
        [DisplayName("日文")]
        [SugarColumn(Length = 150, IsNullable = true)]
        public string? ja_JP { get; set; }

        /// <summary>
        /// 泰国
        /// </summary> 
        [DisplayName("泰文")]
        [SugarColumn(Length = 150, IsNullable = true)]
        public string? th_TH { get; set; }

        /// <summary>
        /// 法国
        /// </summary>
        [SugarColumn(Length = 150, IsNullable = true)]
        [DisplayName("法文")]
        public string? fr_FR { get; set; }

        #endregion 属性

        #region Public 方法

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return "双击展开";
        }
        /// <summary>
        /// 设置语言,用于方便在设置时候更直观的设置语言
        /// </summary>
        /// <param name="lan"></param>
        /// <param name="val"></param>
        public void SetLanguage(Language lan, string? val)
        {
            switch (lan)
            {
                case Language.中文:
                    zh_CN = val;
                    break;
                case Language.English:
                    en_US = val;
                    break;
                case Language.中文_繁体:
                    zh_TW = val;
                    break;
                case Language.日本語:
                    ja_JP = val;
                    break;
                case Language.ไทย:
                    th_TH = val;

                    break;
                case Language.Français:
                    fr_FR = val;

                    break;
                default:
                    break;
            }
        }
        /// <summary>
        /// 设置语言,用于方便在设置时候更直观的设置语言
        /// </summary>
        /// <param name="lan"></param>
        /// <param name="val"></param>
        public void SetLanguage(string? val)
        {
            var lan = App.User.Language;
            switch (lan)
            {
                case Language.中文:
                    zh_CN = val;
                    break;
                case Language.English:
                    en_US = val;
                    break;
                case Language.中文_繁体:
                    zh_TW = val;
                    break;
                case Language.日本語:
                    ja_JP = val;
                    break;
                case Language.ไทย:
                    th_TH = val;

                    break;
                case Language.Français:
                    fr_FR = val;

                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// 获取名字 ufo ,如果为空,就需要把英文(中文)做为键,到Dislangue表中查找,后续可能会把这张表开始就读到内存中,就到内存集合中找
        /// </summary>
        /// <returns></returns>
        public string? GetDisplayName()
        {
            string? lan = "";
            var Language = App.User.Language;
            switch (Language)
            {
                case Language.中文:
                    lan = zh_CN;
                    break; ;
                case Language.English:
                    lan = en_US;
                    break;
                case Language.中文_繁体:
                    lan = zh_TW;
                    break; ;
                case Enums.Language.日本語:
                    lan = ja_JP;
                    break; ;
                case Enums.Language.ไทย:
                    lan = th_TH;
                    break; ;
                case Enums.Language.Français:
                    lan = fr_FR;
                    break; ;
                default:
                    break;
            }

            if (string.IsNullOrEmpty(lan))
            {
                return zh_CN;
                //List<DisLanguage> list = new List<DisLanguage>();
                //var xx = list.Find(x => x.en_US == res).fr_FR;
                ////todo ufo  如果没,就在字典表里面去找,根据en_US来确定,字典表里面也没有的话,就返回en_US本身
            }
            else
            {
                return lan;
            }
        }

        #endregion Public 方法
    }
}
